package com.tdkj.signing;

import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;
import com.tdkj.signing.SigningActivity;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

/**
 * This class echoes a string called from JavaScript.
 */
public class SigningPlugin extends CordovaPlugin {
    public static CallbackContext cbCtx = null;
    private static final int QMrequestCode = 188;

    @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {

        if (action.equals("Signing")) {
            String message = args.getString(0);
            this.f_Signing(message, callbackContext);
            return true;
        }

        return false;
    }

    private void f_Signing(String message, CallbackContext callbackContext) {
        cbCtx = callbackContext;
        if (message != null && message.length() > 0) {
            Intent intent = new Intent(cordova.getActivity().getApplicationContext(), SigningActivity.class);
            intent.putExtra("titleColor", message);
            cordova.startActivityForResult(this,intent, QMrequestCode);
        } else {
            callbackContext.error("null");
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.e("TAG", "requestCode: " + requestCode + "  resultCode=" + resultCode);
        if (requestCode == QMrequestCode) {
            try {
                cbCtx.success(data.getStringExtra("qm_path")+"##"+data.getStringExtra("Sp_path"));
            } catch (Exception e) {
                e.printStackTrace();
                cbCtx.error("null");
            }
        }
    }

}

    
    
        
          
    

    
    
        
        
    

    
    
        
          
    

    
    
        
        
    

